(function(window) {
	window.domUtil = window._ = {
		hasClass: function(obj, cls) {
			return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
		},
		addClass: function(obj, cls) {
			if (!_.hasClass(obj, cls)) obj.className += " " + cls;
		},
		removeClass: function(obj, cls) {
			if (_.hasClass(obj, cls)) {
				var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
				obj.className = obj.className.replace(reg, ' ');
			}
		},
		each: function(arr, callback) {
			if (!arr || arr.length === 0) {
				return;
			}
			if (typeof arr === 'object') {
				if (arr.length > 0) {
					for (var i = 0; i < arr.length; i++) {
						callback.call(arr, arr[i], i);
					}
					return;
				}
				for (var key in arr) {
					callback.call(arr, arr[key], key);
				}
			}
		}
	}

	var selected;

	/**
	 *	切换展示容器
	 */
	var hideAllRouter = function(id) {
		var showBox = document.getElementById(id);
		// 设置title
		document.title = '嗖嗖车位 - ' + showBox.getAttribute('view-title');
		var container = document.getElementById('detail');
		var list = container.getElementsByTagName('section');
		_.each(list, function(item, index) {
			if (item.getAttribute('class')) {
				_.removeClass(item, 'show animated fadeIn');
			}
		});
		_.addClass(showBox, 'show animated fadeIn');
	}

	/**
	 *	处理路由
	 */
	var routerHandler = function(val) {
		hideAllRouter('box-' + val);
	}

	hashRouter({
		'introduce, culture, background, produce, contact': routerHandler
	});
})(window);